home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FPRESET.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  586 b   |  30 lines

  1. /* fpreset.c function, from p. 214 of turbo c bible */
  2. #include<math.h>
  3. #include<stdio.h>
  4. #include<float.h>
  5. #include<setjmp.h>
  6. #include<signal.h>
  7. void myfphandler(int);
  8. jmp_buf this_point;
  9. main()
  10. {
  11.     double a = 1.0, b = 0.0, c;
  12.  
  13.     if(signal(SIGFPE, myfphandler) == SIG_ERR)
  14.     {
  15.         abort();
  16.     }
  17.     if(setjump(this_point) == 0)
  18.     {
  19.         c = a/b;
  20.     }
  21.     printf("recoverd from floating point error\n");
  22. }
  23.     /*------------------------------------------------*/
  24. void myfphandler(int sig)
  25. {
  26.     printf("in handler: signal = %d\n", sig);
  27.         _fpreset();
  28.         longjump(this_point, -1);
  29. }
  30.